<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8" />
  <title>Hello World</title>
  <script src="https://unpkg.com/react@16/umd/react.development.js"></script>
  <script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
  <script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>
  <style>
    .FancyBorder{
      padding:10px 10px;
      border:10px solid;
    }

    .FancyBorder-blue{
      border-color:blue;
    }

    .Dialog-title{
      margin:0;
    }
  </style>
</head>

<body>
  <div id="root"></div>
  <script type="text/babel">

    function FancyBorder(props){
      return (
        <div className={'FancyBorder FancyBorder-' + props.color}>{props.children}</div>
      );
    }

    function Dialog(props){
      return (
        <FancyBorder color="blue">
          <h1 className="Dialog-title">{props.title}</h1>
          <p className="Dialog-message">{props.message}</p>
          {props.children}
        </FancyBorder>
      );
    }

    class SignUpDialog extends React.Component{
      constructor(props){
        super(props);
        this.handleChange = this.handleChange.bind(this);
        this.handleSignUp = this.handleSignUp.bind(this);
        this.state = {login:''};
      }

      handleChange(e){
        this.setState({login:e.target.value});
      }

      handleSignUp(){
        alert(`Welcome aboard, ${this.state.login}!`);
      }

      render(){
        return (
          <Dialog title="Mars Exploration Program" message="How should we refer to you?">
            <input value={this.state.login} onChange={this.handleChange}/>
            <button onClick={this.handleSignUp}>Sign Me Up!</button>
          </Dialog>
        );
      }
    }

    ReactDOM.render(<SignUpDialog/>,document.getElementById('root'));
  </script>
  <!--
      Note: this page is a great way to try React but it's not suitable for production.
      It slowly compiles JSX with Babel in the browser and uses a large development build of React.

      To set up a production-ready React build environment, follow these instructions:
      * https://reactjs.org/docs/add-react-to-a-new-app.html
      * https://reactjs.org/docs/add-react-to-an-existing-app.html

      You can also use React without JSX, in which case you can remove Babel:
      * https://reactjs.org/docs/react-without-jsx.html
      * https://reactjs.org/docs/cdn-links.html
    -->
</body>

</html>